//package org.activoricordi.app.snippet
package edu.ucdavis.fiehnlab.alchemy.alchemyAdmin.snippet

/**
 * Created with IntelliJ IDEA.
 * User: naru
 * Date: 3/28/13
 * Time: 1:12 PM
 * To change this template use File | Settings | File Templates.
 */
import _root_.scala.xml.{NodeSeq, Text}
import _root_.net.liftweb.util._
import _root_.net.liftweb.common._
import _root_.java.util.Date
import  edu.ucdavis.fiehnlab.alchemy.alchemyAdmin.lib._
import Helpers._
import net.liftweb._
import http._
import common._
import util.Helpers._
import net.liftweb.http.SHtml._


class InputCompound {

  def add (xhtml:NodeSeq): NodeSeq ={

    /**
     * initialize all var to Default values
     */
      var compoundName = ""
      var inchiKey = ""
      var origin = ""
      var retentionTime = "0"
      var theoreticalMass = "0"
      var massWindowFactor = "0"
      var expectedIntensity ="0"
      var internalStandard = false
      var comments = ""
      var massSpectra = ""

    /**
     * function to check negative values
     */
    def addCompound() =
      if (retentionTime.toDouble <=0) {
        S.error("Invalid value")
      }else{
        S.redirectTo("/")
      }

    /**
     * bind all compound properties to forum
     */

    bind("entry", xhtml,
          "compoundName" -> SHtml.text(compoundName, compoundName = _),
          "inchiKey" -> SHtml.text(inchiKey, inchiKey = _),
          "origin" -> SHtml.text(origin, origin = _),
          "retentionTime" -> SHtml.text(retentionTime, retentionTime = _),
          "theoreticalMass" -> SHtml.text(theoreticalMass, theoreticalMass = _),
          "massWindowFactor" -> SHtml.text(massWindowFactor, massWindowFactor=_),
          "expectedIntensity" -> SHtml.text(expectedIntensity, expectedIntensity = _),
          "internalStandard" -> SHtml.checkbox(internalStandard, internalStandard = _),
          "comments" -> SHtml.textarea(comments, comments = _ ,"cols" -> "10", "rows" -> "20"),
          "massSpectra" -> SHtml.textarea(massSpectra, massSpectra = _,"cols" -> "20", "rows" -> "20"),
           "submit" -> SHtml.submit("Add Compound",addCompound))


  }
}
